#include <cstdio>
#include <map>
#include <iostream>
using namespace std;

int main()
{
   // freopen("2183.txt","r",stdin);
    int x,y;
    scanf("%d",&x);
    map<int,int> cont;

    cont[1] = x;
    int i = 0;
    while(1)
    {
        i++;
        y = x / 10 % 10000;
        y = y * y;
       // cout << y<<endl;
        y = y % 1000000;

        //cout << y<<endl;
        if (cont.count(y) !=0)break;
        cont[y] = i;
        x = y;
    }

    cout << y << " " << i - cont[y] << " " << i <<endl;
    return 0;
}
